<?php

namespace app\http\middleware;

use think\facade\Cache;
use think\facade\Config;

class AdminAuth
{
    public function handle($request, \Closure $next)
    {
        //Cache::clear();
        $token = $request->token;

        if(!$token){
            return json(['code'=>302,'msg'=>'请登录']);
        }
        list($userName,$password,$rand) = explode("\t",model('common/Staff')->ClientKey($request->token,'DECODE'));
        $request->authName = $userName;
        $request->authPassword = $password;
        $CheckAuth = behavior('app\\admin\\behavior\\CheckAuth'); //验证登录
        if(!$CheckAuth){
            return json(['code'=>302,'msg'=>'请登录']);
        }
        $r = behavior('app\\admin\\behavior\\RbacAuth');  //权限
        if(!$r){
            return json(['code'=>303,'msg'=>'没有权限']);
        }

        return $next($request);
    }
}
